1 /*
2 * Created on 11.jul.2003
3 *
4 */
5 package net.sf.panoptes.module.jmx.connector;
6
7 import java.lang.reflect.Proxy;
8 import java.util.Properties;
9
10 import javax.management.MBeanServerConnection;
11 import javax.naming.Context;
12
13 import mx4j.connector.rmi.RMIConnector;
14 import mx4j.connector.rmi.jrmp.JRMPConnector;
15
16 /***
17 *
18 *
19 * @author Dag Liodden
20 * @version 0.1
21 */
22 public class MX4JJRMPConnector implements MBeanServerConnector {
23
24 private String hostName;
25 private int port;
26
27 public void setProperties(Properties properties) {
28 hostName = (String) properties.get("hostname");
29 port = Integer.parseInt((String) properties.get("port"));
30 }
31
32 public MBeanServerConnection connect() throws Exception {
33
34 Properties props = new Properties();
35 props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");
36 props.setProperty(Context.PROVIDER_URL, "rmi://" + hostName + ":" + port); //System.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
37
38 RMIConnector connector = new JRMPConnector();
39 // Pass in the adaptor's JNDI name, no properties
40 String jndiName = "jrmp";
41 connector.connect(jndiName, props);
42
43 // Get the remote MBeanServer from the connector
44 // And use it as if it is an MBeanServer
45 return (MBeanServerConnection) Proxy.newProxyInstance(connector.getClass().getClassLoader(), new Class[] { javax.management.MBeanServerConnection.class }, new MX4JInvocationHandler(connector.getRemoteMBeanServer()));
46
47 }
48
49 }
This page was automatically generated by Maven